global name "s2_dokrig_test"

global datafile "datacvr" 
global datafilemi "mult_impu"


global main "C:/Users/silvio/Documents/CVR/ryp"
global output "$main/output"  
global data "$main/data"  
global code "$main/code"  
global excel "$main/excel"  
global odata "$data/Intermuestra1-2"  

global coord "$data/coordinates"  
global geocoord "$data/geocoord"  


*1 Fix DGP. Simulation with parameters and best model from best data for SL
cd $main
capture log close
log using "$output/${name}.log", replace

matrix drop _all
set more off

set matsize 1392
scalar nstrata=58                      /*=58, CVR strata*/
scalar signi=2


use "${data}/${datafile}" , replace


sort i perpe k
ren y yy
mkmat yy

forval perpel= 1/3{            /*Original*/
scalar perpeh=`perpel'
run "$code/cvrkrigrun_test"

scalar nmao_full=rowsof(mao_full)
matrix ones=J(1,nmao_full,1)

matrix mao_full=mao_full,ones',ones'

scalar j=1
while j<=nmao_full{
matrix mao_full[j,7]=mao_full[j,3]-mao_full[j,5]
matrix mao_full[j,8]=100*mao_full[j,7]/mao_full[j,5]
scalar j=j+1
}


matrix sum_mao_full=ones*mao_full

scalar j=1
while j<=nmao_full{
matrix mao_full[j,4]=int(sqrt(mao_full[j,4])+0.5)
matrix mao_full[j,6]=int(sqrt(mao_full[j,6])+0.5)
scalar j=j+1
}



matrix sum_mao_full[1,4]=int(sqrt(sum_mao_full[1,4])+0.5)
matrix sum_mao_full[1,6]=int(sqrt(sum_mao_full[1,6])+0.5)
matrix sum_mao_full[1,8]=100*sum_mao_full[1,7]/sum_mao_full[1,5]

matrix list mao_full
matrix list sum_mao_full

}

capture log close
